package com.gwl.concurrent.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Interrupting2 {
	public static void main(String[] args) throws InterruptedException {
		Thread t = new Thread(new Blocked2()); 
		t.start(); 
		TimeUnit.SECONDS.sleep(1); 
		t.interrupt(); 
	}
} 

class BlockedMutex { 
	private Lock lock = new ReentrantLock(); 
	public BlockedMutex() { 
		lock.lock(); 
	} 
	public void f() { 
		try {
			lock.lockInterruptibly(); 
			System.out.println("lock acquired in f()"); 
		} catch (InterruptedException e) {
			System.out.println("InterruptedException"); 
		} 
	}
} 
class Blocked2 implements Runnable {
	BlockedMutex blocked = new BlockedMutex(); 
	@Override
	public void run() {
		blocked.f(); 
	} 
}
